<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>入口</title>
    <link rel="stylesheet" type="text/css" href="./css/aui.css" />
    <link rel="stylesheet" type="text/css" href="./css/swiper.css" />
    <style type="text/css">
        .header {
            width: 100%;
            position: relative;
            height: 278px;
        }

        #index_header {
            position: relative;
            height: 100%;
        }

        .nav {
            width: 100%;
            padding-bottom: 5px;
            overflow: hidden;
        }

        .search {
            width: 100%;
            padding: 0 15px;
            display: flex;
            box-sizing: border-box;
            overflow: hidden;
        }

        .search_inner {
            width: 100%;
            height: 35px;
            background: #FFFFFF;
            display: flex;
            border-radius: 17.5px;
        }

        .search_inner .icon {
            width: 15px;
            height: 14px;
            margin-top: 10.5px;
            margin-left: 9px;
        }

        .search_inner .icon img {
            display: block;
            width: 100%;
            height: 100%;
        }

        .news {
            width: 20px;
            height: 17px;
            margin-top: 9px;
            margin-left: 15px;
            background: url(./image/icon_xiaoxi.png) no-repeat;
            background-size: 100% 100%;
        }

        .search_inner .box_input {
            width: 100%;
            flex: 1;
            padding-left: 9px;
            box-sizing: border-box;
            line-height: 37px;
            font-size: 14px;
            font-family: PingFang SC;
            font-weight: 400;
            color: #999999;
        }

        .nav_item {
            display: flex;
            width: 100%;
            padding: 0 15px;
            justify-content: space-between;
            margin-top: 10px;
        }

        .swiper-slide {
            width: auto!important;
            position: relative;
        }

        .swiper-slide>span {
            display: block;
            color: #fff;
        }

        .swiper-slide span:first-child {
            height: 18px;
            line-height: 16px;
            font-family: "微软雅黑";
            font-size: 13px;
            color: rgb(255, 161, 173);
        }

        .swiper-slide span.text {
            height: 18px;
            line-height: 16px;
            font-family: "微软雅黑";
            font-size: 14px;
            color: #fff!important;
        }

        .swiper-slide span.line {
            /*width: 50%;*/
            width: 100%;
            height: 2px;
            background-color: #fff;
            position: absolute;
            bottom: 0px;
            border-radius: 1px;
            /*left: 50%;
          margin-left: -25%;*/
        }

        .nav_item_l {
            width: 80%;
            flex: 1;
            margin-right: 15px;
            height: 18px;
            line-height: 18px;
            font-family: "微软雅黑";
        }

        .nav_item_r {
            width: 16px;
            height: 16px;
        }

        .nav_item_r img {
            display: block;
            width: 100%;
            height: 100%;
        }

        .app-bg {
            width: 100%;
            background-color: rgb(255, 48, 62);
            overflow: hidden;
        }

        .app-bg-mine {
            width: 100%;
            height: 215px;
            background: linear-gradient(0deg, #AA51FB, #6805FD, #6205FD)!important;
        }

        .mine_head {
            width: 100%;
            padding: 0 15px;
            margin-top: 10px;
            box-sizing: border-box;
            position: relative;
        }

        .mine_head_text {
            width: 100%;
            height: 18px;
            line-height: 18px;
            text-align: center;
            font-size: 16px;
            font-family: PingFang SC;
            font-weight: 500;
            color: #FFFFFF;
        }

        .mine_head_set {
            width: 18px;
            height: 18px;
            position: absolute;
            right: 15px;
            top: 0;
            background: url(./image/set.png) no-repeat;
            background-size: 100% 100%;
            z-index: 99;
        }

        .mine_content {
            width: 100%;
            margin-top: 26px;
            overflow: hidden;
        }

        .head_img {
            width: 48px;
            height: 48px;
            margin: 0 auto;
        }

        .head_img img {
            width: 100%;
            height: 100%;
            display: block;
        }

        .mine_content .username {
            width: 100%;
            height: 15px;
            line-height: 15px;
            color: #fff;
            font-size: 14px;
            text-align: center;
            font-family: PingFang SC;
            font-weight: 500;
            margin-top: 12px;
        }
        /*达人说css*/

        .app-bg-talent {
            width: 100%;
            background: #fff!important;
            overflow: hidden;
        }

        .talentsays {
            width: 100%;
            height: 44px;
            line-height: 44px;
            color: #333333;
            font-size: 17px;
            font-family: PingFang SC;
            text-align: center;
            border: none;
            background-size: 100% 1px;
            background-repeat: no-repeat;
            background-position: bottom;
            background-image: linear-gradient(0, #EEEEEE, #EEEEEE 50%, transparent 50%);
            background-image: -webkit-linear-gradient(90deg, #EEEEEE, #EEEEEE 50%, transparent 50%);
        }
        /*分类头部css*/

        .app-bg-category {
            width: 100%;
            background: linear-gradient(266deg, #7D0DFB, #D115FD);
            overflow: hidden;
        }

        .category_head .title {
            width: 100%;
            height: 44px;
            line-height: 44px;
            box-sizing: border-box;
            font-family: PingFang SC;
            text-align: center;
            overflow: hidden;
            text-overflow: ellipsis;
            z-index: 2;
            color: #fff;
            font-size: 17px;
            /*border: none;
          background-size: 100% 1px;
          background-repeat: no-repeat;
          background-position: right;
          background-image: linear-gradient(0, #EEEEEE, #EEEEEE 50%, transparent 50%);
          background-image: -webkit-linear-gradient(90deg, #EEEEEE, #EEEEEE 50%, transparent 50%);*/
            /*overflow: hidden;*/
        }

        .category {
            width: 84px;
            height: 100%;
            position: fixed;
            /*padding: 0 15px;*/
            box-sizing: border-box;
            background-color: #fff;
            border-right: 0.5px solid #EEEEEE;
            overflow: auto;
        }

        .topmenu {
            width: 100%;
            height: 100%;
            background: #E6E8ED;
            font-family: "微软雅黑";
            /*position: fixed;*/
        }

        .topmenu .swiper-slide {
            width: auto!important;
            position: relative;
        }

        .topmenu .swiper-slide span.ftext {
            display: block;
            font-family: "微软雅黑";
            color: #333333;
            font-size: 15px;
            text-align: center;
            height: 35px;
            line-height: 35px;
            /*border: 1px solid red;*/
        }

        .topmenu .swiper-slide span.Line {
            width: 2px;
            height: 100%;
            background-color: #FF3537;
            position: absolute;
            left: 0;
            top: 0;
            border-radius: 2px;
            display: block;
        }

        .topmenu .swiper-slide span.T {
            color: #FF3537!important;
            background-color: #fff;
            /*padding:5px 0;*/
            display: block;
        }
    </style>
</head>

<body>
    <div id="app" :class="{'app-bg':active_index==0,'app-bg-category':active_index==1,'app-bg-talent':active_index==2,'app-bg-mine':active_index==3}">
        <div id="header" v-if="active_index==0">
            <div class="nav">
                <div class="search">
                    <div class="search_inner" @click='openSearchPage()'>
                        <div class="icon"><img src="./image/search.png" alt=""></div>
                        <div class="box_input">输入商品名或粘贴宝贝标题搜索</div>
                    </div>
                    <div class="news" @click='openMessagePage()'></div>
                </div>

                <div class="nav_item">
                    <div class="nav_item_l">
                        <div class="swiper-container">
                            <div class="swiper-wrapper">
                                <div class="swiper-slide" v-for='(item,index) in navlist' tapmode @click="change_(index)">
                                    <span :class="{'text':isActive_==index}">{{item.cname}}</span>
                                    <span :class="{'line':isActive_==index}"></span>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="nav_item_r" @click='openCategoryPage()'><img src="./image/more_classify.png" alt=""></div>
                </div>
            </div>
        </div>

        <div id="header" class="category_head" v-if="active_index==1">
            <div class="title">超级分类</div>
            <div class="category" id="category">
                <div class="topmenu">
                    <div class="swiper-container swiper2">
                        <div class="swiper-wrapper">
                            <div class="swiper-slide" v-for='(item,index) in good_name_list' tapmode @click="change(index,item.cid)">
                                <span class='ftext' :class="{'T':isActive==index}">{{item.main_name}}</span>
                                <span :class="{'Line':isActive==index}"></span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div id="header" v-if="active_index==2" class="talentsays">达人说</div>
        <!-- 我的 -->
        <div id="header" v-if="active_index==3">
            <div class="mine_head">
                <div class="mine_head_text">个人中心</div>
                <div class="mine_head_set" @click='openSetPage()'></div>
            </div>
            <div class="mine_content">
                <div class="head_img"><img src="./image/head_img.png" alt=""></div>
                <div class="username">{{username}}</div>
            </div>
        </div>
    </div>
</body>
<script type="text/javascript" src="./script/api.js"></script>
<script type="text/javascript" src="./script/cling.js"></script>
<script type="text/javascript" src="./script/vue.js"></script>
<script type="text/javascript" src="./script/swiper.js"></script>
<script type="text/javascript">
    apiready = function() {
        // alert(JSON.stringify(cl.deviceInfo().appVersion))
        api.setStatusBarStyle({
            style: 'dark'
        });
        if ($api.getStorage('userToken')) {
            vm.is_login = true;
        } else {
            vm.is_login = false;
        }
        if (api.systemType == "ios") { // ios 无需调用权限控制

        } else {
            // checkPermission(permissionlist); // android 拉起app权限
            hasPermission(); // android 拉起app权限
        }

        /**
         *
         * 初始化底部tab栏
         * @return {[type]} [description]
         */
        vm.initFooterBar();

        /**
         *
         * 获取首页导航栏分类
         * @return {[type]} [description]
         */
        vm.getIndexCateGory();

        var header = $api.byId('app');
        var headerH = $api.fixStatusBar(header);
        vm.initShowPage(headerH);



        /**
         *
         * 监听回到首页
         * @return {[type]} [description]
         */

        api.addEventListener({
            name: 'backindex'
        }, function(ret, err) {
            if (ret) {
                api.setFrameGroupIndex({
                    name: 'mainFrameGroup',
                    index: 0
                });
                vm.getIndexCateGory()
                vm.active_index = 0;
                vm.initShowPage(headerH);
                var NVTabBar = api.require('NVTabBar');
                NVTabBar.setSelect({
                    index: 3,
                    selected: false,
                });
                NVTabBar.setSelect({
                    index: vm.active_index,
                    selected: true,
                });
            }
        });


        /**
         * [监听导航栏颜色变化]
         * @type {String}
         */
        api.addEventListener({
            name: 'refreshColor'
        }, function(ret, err) {
            if (ret) {
                if (vm.active_index == 0) {
                    document.getElementsByClassName('app-bg')[0].style.backgroundColor = ret.value.color;
                }
            }
        });

        /**
         * [监听登录成功事件]
         * @type {String}
         */
        api.addEventListener({
            name: 'login_success'
        }, function(ret, err) {
            if (ret) {
                vm.is_login = true;
                var token = ret.value.token;
                var mid = ret.value.id;
                $api.setStorage('userToken', token);
                $api.setStorage('mid', mid);
                api.ajax({
                    url: cl.apiServer + 'member/getInfo/' + mid,
                    method: 'get',
                    headers: {
                        token:token
                    }
                }, function(ret, err) {
                    if (ret) {
                        if (ret.code == 0) {
                            $api.setStorage('zfbAccount', ret.data.zfbAccount);
                            $api.setStorage('truename', ret.data.truename);
                            $api.setStorage('userInfo', ret.data);
                            vm.username = ret.data.account.slice(0,3)+"****"+ret.data.account.slice(7,11);
                            cl.closeWin({
                                name: "code_login"
                            });
                        }
                    }
                });
            }
        });
        /**
         * [name监听退出登录]
         * @type {String}
         */
        api.addEventListener({
            name: 'logout_success'
        }, function(ret, err) {
            if (ret) {
                vm.is_login = false;
                vm.username='昵称';
            }
        });

        /**
         * [监听两次返回键退出]
         * @type {String}
         */
        exitan = false;
        api.addEventListener({
            name: 'keyback'
        }, function(ret, err) {
          api.getPrefs({
              key: 'isOpenlayer'
          }, function(ret1, err) {
              if (ret1.value == 1) {
                  var jsfun = 'vm.closeF()';
                  api.execScript({
                      frameName: 'inxcategory_frame',
                      script: jsfun
                  });
              } else {
                if (exitan) {
                    api.closeWidget({
                        silent: true
                    });
                } else {
                    cl.toast({
                        msg: '再按一次退出'
                    });
                    exitan = true;
                    setTimeout(function() {
                        exitan = false;
                    }, 1000)
                }
              }
          });




        });

        /**
         * [监听用户协议]
         * @type {String}
         */
        api.getPrefs({
            key: 'isAgree'
        }, function(ret, err) {
            // alert(JSON.stringify(ret));
            if (!ret.value) {
                api.openFrame({
                    name: 'user_agreement_frame',
                    url: './user_agreement_frame.html',
                    bounces: false,

                    rect: { // 推荐使用Margin布局，用于适配屏幕的动态变化
                        marginTop: 0, // main页面距离win顶部的高度
                        marginBottom: 0, // main页面距离win底部的高度
                        w: 'auto' // main页面的宽度 自适应屏幕宽度
                    },
                    bgColor: 'rgba(0,0,0,0.2)',
                    allowEdit: true,
                    animation: {
                        type: 'flip',
                        subType: 'from_bottom',
                        duration: 300
                    }
                });
            }
        });

        api.addEventListener({
            name: 'sendIdx'
        }, function(ret, err) {
            if (ret) {
                vm.isActive_ = ret.value.index + 1;
                vm.change_(ret.value.index + 1)
                api.setFrameGroupIndex({
                    name: 'SecondCategoryGroup',
                    index: ret.value.index + 1,
                    scroll: true
                });
            }
        });


        //获取app基本信息
        api.ajax({
            url: cl.apiServer + 'cpssystemConfig/getAPPInfo',
            method: 'post',
            headers: {
                token: ''
            }
        }, function(ret, err) {
            if(ret.code==0){
               $api.setStorage('appinfo', ret.data);
            }
        })

        api.addEventListener({
            name: 'resume'
        }, function(ret, err){
          // alert(JSON.stringify(ret))
          api.ajax({
              url: cl.apiServer + 'cpssystemConfig/getAPPInfo',
              method: 'post',
              headers: {
                  token:cl.userToken
              }
          }, function(ret1, err) {
              if(ret1.code==0){
                // alert(JSON.stringify(ret1.data))
                 $api.setStorage('appinfo', ret1.data);
              }
          })
        });

        api.addEventListener({
            name: 'pause'
        }, function(ret, err){
          // alert(JSON.stringify(ret))
          api.ajax({
              url: cl.apiServer + 'cpssystemConfig/getAPPInfo',
              method: 'post',
              headers: {
                  token:cl.userToken
              }
          }, function(ret1, err) {
              if(ret1.code==0){
                // alert(JSON.stringify(ret1.data))
                 $api.setStorage('appinfo', ret1.data);
              }
          })
        });


        vm.getSuperCategory();

         


    };
    var vm = new Vue({
        el: "#app",
        data: {
            active_index: 0, // 控制显示不同页面头部
            good_name_list: [], //超级分类列表
            isActive: 0,
            isActive_: 0,
            navlist: [],
            is_login: false, //用户是否登录
            username:'',
            isflag:true
        },
        methods: {
            /**
             *
             * 获取首页导航栏分类
             * @return {[type]} [description]
             */
            getIndexCateGory: function() {
                api.ajax({
                    url: cl.apiServer + 'category/getCategoryList',
                    method: 'post',
                    headers: {
                        'Content-Type': 'application/json;charset=utf-8',
                        token: ''
                    },
                    data: {
                        body: {
                            parentId: 0,
                            ctype: 1,
                            version:cl.deviceInfo().appVersion,
                            mobileInfo:cl.systemType()
                        }
                    }
                }, function(ret, err) {
                    if (ret) {
                        if (ret.code == 0) {
                            vm.navHeadLength = ret.data.length;
                            var classifyArr = [{
                                cname: '精选',
                                cid: ''
                            }];

                            for (var i = 0; i < ret.data.length; i++) {
                                var obj = {};
                                obj.cid = ret.data[i].cid;
                                obj.cname = ret.data[i].cname;
                                classifyArr.push(obj);
                            }
                            vm.navlist = classifyArr;
                            setTimeout(function() {
                                var swiper = new Swiper('.swiper-container', {
                                    spaceBetween: 20,
                                    slidesPerView: 'auto',
                                    freeMode: true
                                }, 1000);
                            });
                        }
                    }
                });
            },
            change_: function(index) {
                cl.closeFrame({
                    name: 'inxcategory_frame'
                })
                vm.isActive_ = index;
                var header = $api.byId('app');
                var headerH = $api.fixStatusBar(header);
                if (index == 0) {
                    vm.initShowPage(headerH);
                } else {
                    vm.initHeadNavPage(headerH);
                    setTimeout(function() {
                        api.setFrameGroupIndex({
                            name: 'SecondCategoryGroup',
                            index: index,
                            scroll: true
                        });
                    }, 0)
                }
            },
            initHeadNavPage: function(headerH) {
                var frames = [];
                for (var i = 0; i < vm.navlist.length; i++) {
                    frames.push({
                        name: 'second_category_' + i,
                        url: './html/main/second_category.html',
                        bounces: true,
                        bgColor: "#FAF9F9",
                        pageParam: {
                            cid: vm.navlist[i].cid
                        }
                    })
                }
                api.openFrameGroup({
                    name: 'SecondCategoryGroup',
                    background: '#FAF9F9',
                    scrollEnabled: false,
                    rect: {
                        marginTop: headerH,
                        marginBottom: 49 + api.safeArea.bottom, // main页面距离win底部的高度
                        w: 'auto'
                    },
                    index: 0,
                    frames: frames
                }, function(ret, err) {

                });
            },
            /**
             *
             * 获取超级分类列表
             * @return {[type]} [description]
             */
            getSuperCategory: function() {
                api.ajax({
                    url: cl.apiServer + 'category/getSuperClassify',
                    method: 'post',
                    headers: {
                        token: ''
                    }
                }, function(ret, err) {
                    if (ret) {
                        if (ret.code == 0) {
                            vm.good_name_list = ret.data;
                        }
                    }
                })
            },

            openCategoryPage: function() {
              // alert(vm.isflag)
              if(vm.isflag){
                api.setPrefs({
                    key: 'isOpenlayer',
                    value: '1'
                });
                vm.isflag = false;
                var header = $api.byId('app');
                $api.fixStatusBar($api.byId('app'));
                var offsetH = $api.offset($api.byId('app')).h;
                api.openFrame({
                    name: 'inxcategory_frame',
                    url: './html/main/inxcategory_frame.html',
                    rect: {
                        marginTop: offsetH,
                        marginBottom: api.safeArea.bottom, // main页面距离win底部的高度
                        w: 'auto'
                    },
                    bounces: false,
                    bgColor: "rgba(0, 0, 0, 0.2)",
                    vScrollBarEnabled: true,
                    hScrollBarEnabled: true,
                    animation: {
                        type: 'movein',
                        subType: 'from_right',
                        duration: 300
                    }
                });
              }else{
                api.removePrefs({
                    key: 'isOpenlayer'
                });
                vm.isflag = true;
                cl.closeFrame({
                    name: 'inxcategory_frame'
                })
              }

            },

            /**
             *
             * 初始化底部导航栏
             * @return {[type]} [description]
             */

            initFooterBar: function() {
                var NVTabBar = api.require('NVTabBar');
                NVTabBar.open({
                    styles: {
                        bg: '#fff',
                        h: 49,
                        dividingLine: {
                            width: 0.5,
                            color: '#ccc'
                        },
                        badge: {
                            bgColor: '#FF0000',
                            numColor: '#fff',
                            size: 6.0,
                            centerX: 75,
                            centerY: 2
                        }
                    },
                    items: [{
                        w: api.winWidth / 4.0,
                        bg: {
                            marginB: -2,
                            image: ''
                        },
                        iconRect: {
                            w: 29,
                            h: 29,
                        },
                        icon: {
                            normal: 'widget://image/icon_tab_01.png',
                            highlight: 'widget://image/icon_tab_01_hover.png',
                            selected: 'widget://image/icon_tab_01_hover.png'
                        },
                        title: {
                            text: '首页',
                            size: 11.0,
                            normal: '#c8c8c8',
                            selected: '#db0a17',
                            marginB: 4.0
                        }
                    }, {
                        w: api.winWidth / 4.0,
                        bg: {
                            marginB: -2,
                            image: 'rgba(255,255,255,1)'
                        },
                        iconRect: {
                          w: 29,
                          h: 29,
                        },
                        icon: {
                            normal: 'widget://image/icon_tab_04.png',
                            highlight: 'widget://image/icon_tab_04_hover.png',
                            selected: 'widget://image/icon_tab_04_hover.png'
                        },
                        title: {
                            text: '超级分类',
                            size: 11.0,
                            normal: '#c8c8c8',
                            selected: '#db0a17',
                            marginB: 3.0
                        }
                    }, {
                        w: api.winWidth / 4.0,
                        bg: {
                            marginB: -2,
                            image: 'rgba(255,255,255,1)'
                        },
                        iconRect: {
                          w: 29,
                          h: 29,
                        },
                        icon: {
                            normal: 'widget://image/icon_tab_02.png',
                            highlight: 'widget://image/icon_tab_02_hover.png',
                            selected: 'widget://image/icon_tab_02_hover.png'
                        },
                        title: {
                            text: '达人说',
                            size: 11.0,
                            normal: '#c8c8c8',
                            selected: '#db0a17',
                            marginB: 3.0
                        }
                    }, {
                        w: api.winWidth / 4.0,
                        bg: {
                            marginB: -2,
                            image: 'rgba(255,255,255,1)'
                        },
                        iconRect: {
                          w: 29,
                          h: 29,
                        },
                        icon: {
                            normal: 'widget://image/icon_tab_mine.png',
                            highlight: 'widget://image/icon_tab_mine_hover.png',
                            selected: 'widget://image/icon_tab_mine_hover.png'
                        },
                        title: {
                            text: '我的',
                            size: 11.0,
                            normal: '#c8c8c8',
                            selected: '#db0a17',
                            marginB: 3.0
                        }
                    }],
                    selectedIndex: 0
                }, function(ret, err) {
                    if (ret.eventType == 'click') {
                        if (ret.index == 3) {
                            if (vm.is_login) {
                                api.setFrameGroupIndex({
                                    name: 'mainFrameGroup',
                                    index: ret.index
                                });
                                vm.active_index = ret.index;
                                vm.setFrameGroup(ret.index, true);
                            } else {
                                var NVTabBar = api.require('NVTabBar');
                                NVTabBar.setSelect({
                                    index: 3,
                                    selected: false,
                                });
                                NVTabBar.setSelect({
                                    index: vm.active_index,
                                    selected: true,
                                });
                                cl.openWin({
                                    name: './html/login/code_login'
                                })
                            }
                        } else {
                            api.setFrameGroupIndex({
                                name: 'mainFrameGroup',
                                index: ret.index
                            });
                            setTimeout(function() {
                                var swiper = new Swiper('.swiper2', {
                                    spaceBetween:5,
                                    slidesPerView: 'auto',
                                    direction: 'vertical',
                                    freeMode: true
                                }, 10);
                            });
                            vm.active_index = ret.index;
                            vm.setFrameGroup(ret.index, true);
                        }

                    }
                });
            },
            initShowPage: function(headerHeight) {
                api.openFrameGroup({
                    name: 'mainFrameGroup',
                    background: '#FAF9F9',
                    scrollEnabled: false,
                    rect: {
                        x: 0,
                        y: headerHeight,
                        w: 'auto',
                        h: api.winHeight - headerHeight - 49 - api.safeArea.bottom
                    },
                    index: 0,
                    preload: 4,
                    frames: [{
                        name: 'index_frame',
                        url: './html/main/index_frame.html',
                        bgColor: '#FAF9F9',
                        bounces: true,
                        customRefreshHeader: 'UIPullRefreshMotive',
                    }, {
                        name: 'category_frame',
                        url: '',
                        bgColor: '#FAF9F9',
                        bounces: true
                    }, {
                        name: 'talent_say_frame',
                        url: './html/main/talent_say_frame.html',
                        bgColor: '#FAF9F9',
                        bounces: true
                    }, {
                        name: 'mine_frame',
                        url: './html/mine/mine_frame.html',
                        bgColor: '#FAF9F9',
                        bounces: false
                    }]
                }, function(ret, err) {


                });

            },
            setFrameGroup: function(index, isclick_) {
                if (isclick_) {
                    if (index == 0) {
                        setTimeout(function() {
                            var header = $api.byId('app');
                            var headerH = $api.fixStatusBar(header);
                            var rect = {
                                x: 0,
                                y: headerH,
                                w: 'auto',
                                h: api.winHeight - 49 - api.safeArea.bottom-headerH
                            }
                            api.setFrameGroupAttr({
                                name: 'mainFrameGroup',
                                rect: rect,
                                hidden: false,
                            });
                            api.setFrameGroupAttr({
                                name: 'cateGoryGroup',
                                hidden: true,
                            });
                            api.setFrameGroupAttr({
                                name: 'SecondCategoryGroup',
                                hidden:false,
                            });

                            vm.getIndexCateGory();
                            document.getElementsByClassName('app-bg')[0].style.backgroundColor = 'red';
                            api.sendEvent({
                                name: 'fixedColor',
                            });

                        }, 0)
                    }
                    if (index == 1) {
                        setTimeout(function() {
                            api.setFrameGroupAttr({
                                name: 'mainFrameGroup',
                                hidden: true,
                            });
                            api.setFrameGroupAttr({
                                name: 'SecondCategoryGroup',
                                hidden: true,
                            });
                            var header = $api.byId('app');
                            var headerH = $api.fixStatusBar(header);
                            var category = $api.byId('category');
                            var categoryH = $api.offset(category).h;
                            // alert(JSON.stringify(vm.good_name_list))
                            var frames = [];
                            for (var i = 0; i < vm.good_name_list.length; i++) {
                                frames.push({
                                    name: '_category_frame_' + i,
                                    url: './html/main/_category_frame.html',
                                    bounces: true,
                                    bgColor: "#FAF9F9",
                                    pageParam: {
                                        cid: vm.good_name_list[i].cid,
                                        name: vm.good_name_list[i].main_name
                                    }
                                })
                            }
                            api.openFrameGroup({
                                name: 'cateGoryGroup',
                                background: '#FAF9F9',
                                scrollEnabled: false,
                                rect: {
                                    marginTop: headerH,
                                    marginBottom: 49 + api.safeArea.bottom, // main页面距离win底部的高度
                                    x: 84
                                },
                                index: 0,
                                frames: frames,
                                preload: 0
                            }, function(ret, err) {
                                if (ret) {

                                }
                            });
                        }, 0)
                    }

                    if (index == 2) {
                        setTimeout(function() {
                            var header = $api.byId('app');
                            var headerH = $api.fixStatusBar(header);
                            var rect = {
                                x: 0,
                                y: headerH,
                                w: 'auto',
                                h: api.winHeight - 49 - api.safeArea.bottom- headerH
                            }
                            api.setFrameGroupAttr({
                                name: 'mainFrameGroup',
                                rect: rect,
                                hidden:false
                            });
                            api.setFrameGroupAttr({
                                name: 'cateGoryGroup',
                                hidden: true,
                            });
                            api.setFrameGroupAttr({
                                name: 'SecondCategoryGroup',
                                hidden: true,
                            });
                        }, 0)
                    }

                    if (index == 3) {
                        if(cl.userInfo){
                          vm.username = cl.userInfo.account.slice(0,3)+"****"+cl.userInfo.account.slice(7,11);
                        }

                        setTimeout(function() {
                            var header = $api.byId('app');
                            var headerH = $api.fixStatusBar(header);
                            var rect = {
                                x: 0,
                                y: headerH,
                                w: 'auto',
                                h: api.winHeight - 49 - api.safeArea.bottom-headerH
                            }
                            api.setFrameGroupAttr({
                                name: 'mainFrameGroup',
                                rect: rect,
                                hidden:false
                            });
                            api.setFrameGroupAttr({
                                name: 'cateGoryGroup',
                                hidden: true,
                            });
                            api.setFrameGroupAttr({
                                name: 'SecondCategoryGroup',
                                hidden: true,
                            });
                        }, 0)
                    }
                }
            },
            change: function(index) {
                vm.isActive = index;
                api.setFrameGroupIndex({
                    name: 'cateGoryGroup',
                    index: index,
                    scroll: true
                });

            },
            openSearchPage: function() {
                cl.openWin({
                    name: './html/main/search'
                });
            },
            openGoodsDetailsPage: function() {
                cl.openWin({
                    name: './html/main/package_mail'
                })
            },
            openSetPage: function() {
                cl.openWin({
                    name: './html/mine/set'
                })
            },
            openMessagePage: function() {
                cl.openWin({
                    name: './html/main/message'
                })
            }
        }
    })


    var permissionlist = ['storage','phone']; //
    var request_permission = []; //
    function hasPermission() { // 判断权限是否存在
        var resultList = api.hasPermission({
            list: permissionlist
        });
        for (var i = 0; i < resultList.length; i++) {
            if (!resultList[i].granted) {
                request_permission.push(resultList[i].name);
            }
        }
        if (request_permission.length) { // 拉起权限
            requestPermission();
        }
    }
    function requestPermission() {
        // console.log('未开启权限'+ JSON.stringify(request_permission));
        api.requestPermission({
            list: request_permission,
            code: 1
        }, function(ret, err) {

        });
    }
</script>

</html>
